/*
--------------------------------------------------------------------------------
	This do file conducts the tests described and creates Figures 1A, 1B, 2A, 2B
	and 3A, 3B, 3C from "Lies in politics: A study of politicians' preferences for truth-telling".
	Before running this do file, readers should update the directory below 
	called "Home" to where the "ReplicationPackage" folder is located.
	
	Paper: "Lies in politics: A study of politicians' preferences for truth-telling"
	Authors: Katharina A. Janezic, Aina Gallego
	Corresponding author: Aina Gallego, agallego@ibei.org
	
	Last changed: June 6, 2020
--------------------------------------------------------------------------------
*/

*----- 0: Housekeeping
clear all
version 13
set more off
//ssc install grstyle // install 'grstyle' package


*------------------------------------------------------------------------------*
/* PLEASE UPDATE THE DIRECTORY HERE */
/* For Mac Users */
//cd "Users/.../Replication/code"

/* For Windows Users */
//cd "C:\...\Replication\code"
*------------------------------------------------------------------------------*

*------------------------------------------------------------------------------*
*----- Load data
use "./dataRepl.dta"

*----- subsample used
drop if interestreport==. //5 observations
drop if honestytime_cutoff==1 //spent less or equal to 5 seconds on answering honesty question
drop if honestytime_cutoff==3 | honestytime_cutoff==4 //spent more than 90 seconds on answering honesty question

*------------------------------------------------------------------------------*

* Define custom look for figures
grstyle init
grstyle color background white
grstyle color p1bar navy
grstyle color p2bar maroon

*------------------------------------------------------------------------------*
*---- 1: Statistical tests of whether overall isCara results different from 50%
*** Average results for heads & tails
tab iscara //0: 32%, 1: 68%

* tabulate percentage of each interest group
tab interestreport //1: 2.4%, 2: 10.1%, 3: 39.8%, 4: 47.7%


*** Binomial test, 1-sided and 2-sided
bitest iscara ==0.5

*** Interest report
bitest iscara ==0.5 if interestreport==1 // not interested
bitest iscara ==0.5 if interestreport==2 // somewhat interested
bitest iscara ==0.5 if interestreport==3 // interested
bitest iscara ==0.5 if interestreport==4 // very interested



*---- 2: Statistical test of whether different from 50% for each category
*---- Binomial

*** Gender
bitest iscara ==0.5 if gender==0 // male
bitest iscara ==0.5 if gender==1 // female

*** Party membership
bitest iscara ==0.5 if isMajorParty==0 // not member of major party
bitest iscara ==0.5 if isMajorParty==1 // member of major party

*** Reelection
bitest iscara ==0.5 if reelected==0 // not reelected
bitest iscara ==0.5 if reelected==1 // reelected

bitest iscara ==0.5 if ranagain==0 // did not rerun for reelection
bitest iscara ==0.5 if ranagain==1 // did rerun for reelection

bitest iscara ==0.5 if saysRunAgain==0 // says does not want to be reelected
bitest iscara ==0.5 if saysRunAgain==1 // says wants to be reelected



*---- 3: Statistical tests of whether categories are signif. different from each other
*---- T- test: use t-test as we only have 2 categories that we can test against each other

*** Gender 
ttest iscara, by(gender)

*** Party membership
ttest iscara, by(isMajorParty)

*** Reelection
ttest iscara, by(reelected)
ttest iscara, by(ranagain)
ttest iscara, by(saysRunAgain)

*** ttest of whether "tails" and "heads" reporting mayors have different rates of whether they ran for reelection
ttest ranagain, by(iscara)

*** Comparison of those who report wanting to run again and those who actually rerun
tab saysRunAgain ranagain
sum iscara if saysRunAgain==0 & ranagain==1
sum iscara if saysRunAgain==1 & ranagain==0
sum iscara if saysRunAgain==1 & ranagain==1
sum iscara if saysRunAgain==0 & ranagain==0


*------------------------------------------------------------------------------*
*----- 4: Figure 1

//NOTE: FOR THE SIGNIFICANCE STARS, SEE T-TEST RESULTS ABOVE


* HEAD REPORTS FOR WHOLE POPULATION (Figure 1A)
preserve
gen x = 1/_N
collapse (sum) meancara=x (count) n=x, by(iscara)
replace meancara = meancara*100
gen iscara_figure = 1 - iscara // STATA cannot plot value 1 to the left of value 0, therefore need to reverse iscara

graph twoway (bar meancara iscara_figure if iscara_figure==0, barw(.95)) (bar meancara iscara_figure if iscara_figure==1, barw(.95)) ///
(function y=50, ra(-0.6 1.6) lcolor(cranberry)), ///
xlabel(0 "Heads" 1 "Tails", noticks) ylab(0(20)80) ///
ytitle("in %") xtitle("") title("Percentage of Head Reports") ///
text(71 0 "68%")  text(35.2 1 "32%") ///
text(71 0.15 "***")  text(35.2 1.15 "***") ///
legend(off) plotregion(margin(8 8 0 3))
graph export heads.pdf, replace
restore

* HEAD REPORTS BY INTEREST IN REPORT (Figure 1A)
preserve
collapse (mean) meancara=iscara (sd) sdcara=iscara (count) n=iscara, by(interestreport)
gen conf_lo = (meancara - (sdcara/sqrt(n))) * 100
gen conf_hi = (meancara + (sdcara/sqrt(n))) * 100
replace meancara = meancara*100

graph twoway (bar meancara interestreport if interestreport==1, barw(.95)) (bar meancara interestreport if interestreport==2, barw(.95)) ///
(bar meancara interestreport if interestreport==3, barw(.95)) (bar meancara interestreport if interestreport==4, barw(.95)) ///
(rcap conf_hi conf_lo interestreport, lcolor(black)) (function y=50, ra(0.5 4.5)), ///
xlabel( 1 "Not interested" 2 "Hardly" 3 "Quite" 4 "Very", noticks) ylab(35(5)80) ///
ytitle("in %") xtitle("") title("Percentage of Head Reports by Interest in Report") ///
text(69.95 3 "***") text(78.6 4 "***") ///
text(36 1 "2.4%", color(white))  text(36 2 "10.1%", color(white)) text(36 3 "39.8%", color(white)) text(36 4 "47.7%", color(white)) ///
legend(off) plotregion(margin(15 15 0 3))
graph export heads_interestReported.pdf, replace
restore  

*------------------------------------------------------------------------------*
*----- 5: Figure 2

//NOTE: FOR THE SIGNIFICANCE STARS, SEE T-TEST RESULTS ABOVE

* GENDER (Figure 2A)
preserve
gen male = 0 // to improve figure's formatting
replace male = 0 if gender==1
replace male = 1 if gender==0

collapse (mean) meancara=iscara (sd) sdcara=iscara (count) n=iscara, by(male)
gen conf_lo = (meancara - (sdcara/sqrt(n))) * 100
gen conf_hi = (meancara + (sdcara/sqrt(n))) * 100
replace meancara = meancara*100

graph twoway (bar meancara male if male==0, barw(.95)) (bar meancara male if male==1, barw(.95)) ///
(rcap conf_hi conf_lo male, lcolor(black)), ///
xlabel( 0 "Female" 1 "Male", noticks) ylab(50(5)75) ///
ytitle("in %") xtitle("") title("Percentage of Head Reports by Gender") ///
legend(off) plotregion(margin(15 15 0 3))
graph export gender.pdf, replace
restore 


* PARTY (Figure 2B)
preserve
collapse (mean) meancara=iscara (sd) sdcara=iscara (count) n=iscara, by(isMajorParty)
gen conf_lo = (meancara - (sdcara/sqrt(n))) * 100
gen conf_hi = (meancara + (sdcara/sqrt(n))) * 100
replace meancara = meancara*100

graph twoway (bar meancara isMajorParty if isMajorParty==0, barw(.95)) (bar meancara isMajorParty if isMajorParty==1, barw(.95)) ///
(rcap conf_hi conf_lo isMajorParty, lcolor(black)), ///
xlabel( 0 "Small Parties" 1 "Major Parties", noticks) ylab(50(5)75) ///
ytitle("in %") xtitle("") title("Percentage of Head Reports by Party Membership") ///
text(66.65 0 "**")  text(73.9 1 "**") ///
legend(off) graphregion(color(white)) bgcolor(white) plotregion(margin(15 15 0 3))
graph export party.pdf, replace
restore

*------------------------------------------------------------------------------*
*----- 6: Figure 3

* DESIRE TO RERUN (Figure 3A)
preserve
drop if saysRunAgain==.
collapse (mean) meancara=iscara (sd) sdcara=iscara (count) n=iscara, by(saysRunAgain)
gen conf_lo = (meancara - (sdcara/sqrt(n))) * 100
gen conf_hi = (meancara + (sdcara/sqrt(n))) * 100
replace meancara = meancara*100

graph twoway (bar meancara saysRunAgain if saysRunAgain==0, barw(.95)) (bar meancara saysRunAgain if saysRunAgain==1, barw(.95)) ///
(rcap conf_hi conf_lo saysRunAgain, lcolor(black)), ///
xlabel( 0 "No" 1 "Yes", noticks) ylab(50(5)75) ///
ytitle("in %") xtitle("") title("Percentage of Head Reports by Desire to Rerun in 2019") ///
legend(off) graphregion(color(white)) bgcolor(white) plotregion(margin(15 15 0 3))
graph export saysRunAgain.pdf, replace
restore

* RAN FOR REELECTION (Figure 3B)
preserve
drop if ranagain==.
collapse (mean) meancara=iscara (sd) sdcara=iscara (count) n=iscara, by(ranagain)
gen conf_lo = (meancara - (sdcara/sqrt(n))) * 100
gen conf_hi = (meancara + (sdcara/sqrt(n))) * 100
replace meancara = meancara*100

graph twoway (bar meancara ranagain if ranagain==0, barw(.95)) (bar meancara ranagain if ranagain==1, barw(.95)) ///
(rcap conf_hi conf_lo ranagain, lcolor(black)), ///
xlabel( 0 "No" 1 "Yes", noticks) ylab(50(5)75) ///
ytitle("in %") xtitle("") title("Percentage of Head Reports by Rerunning in 2019") ///
legend(off) graphregion(color(white)) bgcolor(white) plotregion(margin(15 15 0 3))
graph export ranagain.pdf, replace
restore

* REELECTION (Figure 3C)
preserve
drop if reelected==.
collapse (mean) meancara=iscara (sd) sdcara=iscara (count) n=iscara, by(reelected)
gen conf_lo = (meancara - (sdcara/sqrt(n))) * 100
gen conf_hi = (meancara + (sdcara/sqrt(n))) * 100
replace meancara = meancara*100

graph twoway (bar meancara reelected if reelected==0, barw(.95)) (bar meancara reelected if reelected==1, barw(.95)) ///
(rcap conf_hi conf_lo reelected, lcolor(black)), ///
xlabel( 0 "Not Reelected" 1 "Reelected", noticks) ylab(50(5)75) ///
ytitle("in %") xtitle("") title("Percentage of Head Reports by Reelection in 2019") ///
text(66.35 0 "**")  text(73.2 1 "**") ///
legend(off) graphregion(color(white)) bgcolor(white) plotregion(margin(15 15 0 3))
graph export reelection.pdf, replace
restore

